Micron Document
🌎 rns.kin.earth git 🌍

Node / dev / reticulum / commits / a3bee4b

Commit a3bee4baa9daf21e240058df86623a30e08a2d52


Parents : fab83ec
Author : Mark Qvist <mark@unsigned.io>
Date : 2023-05-04T17:55:58+02:00

Removed netifaces dependency from AutoInterface

Changes

1 files changed, 17 insertions(+), 15 deletions(-)


Diff

diff --git a/RNS/Interfaces/AutoInterface.py b/RNS/Interfaces/AutoInterface.py
index aeb45fa6..063a3a01 100644
--- a/RNS/Interfaces/AutoInterface.py
+++ b/RNS/Interfaces/AutoInterface.py
@@ -62,16 +62,18 @@ class AutoInterface(Interface):
link_local_addr = re.sub(r"fe80:[0-9a-f]*::","fe80::", link_local_addr)
return link_local_addr
+ def list_interfaces(self):
+ ifs = self.netinfo.interfaces()
+ return ifs
+
+ def list_addresses(self, ifname):
+ ifas = self.netinfo.ifaddresses(ifname)
+ return ifas
+
def __init__(self, owner, name, group_id=None, discovery_scope=None, discovery_port=None, data_port=None, allowed_interfaces=None, ignored_interfaces=None, configured_bitrate=None):
- import importlib
- if importlib.util.find_spec('netifaces') != None:
- import netifaces
- else:
- RNS.log("Using AutoInterface requires the netifaces module.", RNS.LOG_CRITICAL)
- RNS.log("You can install it with the command: python3 -m pip install netifaces", RNS.LOG_CRITICAL)
- RNS.panic()
+ from RNS.vendor.ifaddr import niwrapper
+ self.netinfo = niwrapper
- self.netifaces = netifaces
self.rxb = 0
self.txb = 0
@@ -148,7 +150,7 @@ class AutoInterface(Interface):
self.mcast_discovery_address = "ff1"+self.discovery_scope+":"+gt
suitable_interfaces = 0
- for ifname in self.netifaces.interfaces():
+ for ifname in self.list_interfaces():
if RNS.vendor.platformutils.is_darwin() and ifname in AutoInterface.DARWIN_IGNORE_IFS and not ifname in self.allowed_interfaces:
RNS.log(str(self)+" skipping Darwin AWDL or tethering interface "+str(ifname), RNS.LOG_EXTREME)
elif RNS.vendor.platformutils.is_darwin() and ifname == "lo0":
@@ -163,10 +165,10 @@ class AutoInterface(Interface):
if len(self.allowed_interfaces) > 0 and not ifname in self.allowed_interfaces:
RNS.log(str(self)+" ignoring interface "+str(ifname)+" since it was not allowed", RNS.LOG_EXTREME)
else:
- addresses = self.netifaces.ifaddresses(ifname)
- if self.netifaces.AF_INET6 in addresses:
+ addresses = self.list_addresses(ifname)
+ if self.netinfo.AF_INET6 in addresses:
link_local_addr = None
- for address in addresses[self.netifaces.AF_INET6]:
+ for address in addresses[self.netinfo.AF_INET6]:
if "addr" in address:
if address["addr"].startswith("fe80:"):
link_local_addr = self.descope_linklocal(address["addr"])
@@ -287,10 +289,10 @@ class AutoInterface(Interface):
for ifname in self.adopted_interfaces:
# Check that the link-local address has not changed
try:
- addresses = self.netifaces.ifaddresses(ifname)
- if self.netifaces.AF_INET6 in addresses:
+ addresses = self.list_addresses(ifname)
+ if self.netinfo.AF_INET6 in addresses:
link_local_addr = None
- for address in addresses[self.netifaces.AF_INET6]:
+ for address in addresses[self.netinfo.AF_INET6]:
if "addr" in address:
if address["addr"].startswith("fe80:"):
link_local_addr = self.descope_linklocal(address["addr"])

Served by rngit 1.5.2 - Generated in 0.04s